package org.deadline.service.baseapp;

import java.util.List;
import org.deadline.model.baseapp.Event;
import org.deadline.repository.baseapp.EventRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class EventServiceImpl implements EventService {

	@Autowired
    EventRepository eventRepository;

	public long countAllEvents() {
        return eventRepository.count();
    }

	public void deleteEvent(Event event) {
        eventRepository.delete(event);
    }

	public Event findEvent(Long id) {
        return eventRepository.findOne(id);
    }

	public List<Event> findAllEvents() {
        return eventRepository.findAll();
    }

	public List<Event> findEventEntries(int firstResult, int maxResults) {
        return eventRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveEvent(Event event) {
        eventRepository.save(event);
    }

	public Event updateEvent(Event event) {
        return eventRepository.save(event);
    }
}
